package com.myPlaneGame.obj;

import com.myPlaneGame.GameCreate;
import com.myPlaneGame.Utils.GameUtils;

import java.awt.*;

public class BossObj extends GameObj{
    //血量属性
    int health=500;

    public BossObj() {
        super();
    }

    public BossObj(Image img, int width, int height, int x, int y, double speed, GameCreate frame) {
        super(img, width, height, x, y, speed, frame);
    }

    public BossObj(Image img, int x, int y, double speed) {
        super(img, x, y, speed);
    }

    public BossObj(int x, int y) {
        super(x, y);
    }

    @Override
    public void paintSelf(Graphics g) {
        super.paintSelf(g);
        if(y<40){
            y+=speed;
        }else {
            x+=speed;
            //当boss触碰到边界时候，就改变速度的方向使其左右往返
            if(x<0||x>360){
                speed=-speed;
            }
        }
        //1.敌方boss和我方一级子弹碰撞后，我方子弹消失(boss血量为0就消失)
        for (ShellObj shellObj : GameUtils.shellObjList) {
            if (this.getRec().intersects(shellObj.getRec()) && health > 0) {
                shellObj.setX(-100);
                shellObj.setY(-100);
                GameUtils.removeList.add(shellObj);
                health--;
            } else if (this.getRec().intersects(shellObj.getRec()) && health <= 0) {
                //boss生命值为0之后出现爆炸动画
                ExplodeObj explodeObj = new ExplodeObj(x, y);
                GameUtils.explodeObjList.add(explodeObj);
                GameUtils.removeList.add(explodeObj);

                shellObj.setX(-100);
                shellObj.setY(-100);
                this.x = -200;
                this.y = -200;
                GameUtils.removeList.add(this);
                GameCreate.score+=30;

                //游戏胜利（boss血量为0）
                GameCreate.state=4;
            }
        }
        //2.敌方boss和我方二级子弹碰撞后，我方子弹消失(boss血量为0就消失)
        for (DoubleShellObj doubleShellObj : GameUtils.doubleShellObjList) {
            if (this.getRec().intersects(doubleShellObj.getRec()) && health > 0) {
                doubleShellObj.setX(-100);
                doubleShellObj.setY(-100);
                GameUtils.removeList.add(doubleShellObj);
                health-=2;
            } else if (this.getRec().intersects(doubleShellObj.getRec())) {
                //boss生命值为0之后出现爆炸动画
                ExplodeObj explodeObj = new ExplodeObj(x, y);
                GameUtils.explodeObjList.add(explodeObj);
                GameUtils.removeList.add(explodeObj);

                doubleShellObj.setX(-100);
                doubleShellObj.setY(-100);
                this.x = -200;
                this.y = -200;
                GameUtils.removeList.add(this);
                GameCreate.score+=30;

                //游戏胜利（boss血量为0）
                GameCreate.state=4;
            }
        }
        //3.敌方boss和我方三级子弹碰撞后，我方子弹消失(boss血量为0就消失)
        for (TripleShellObj tripleShellObj : GameUtils.tripleShellObjList) {
            if (this.getRec().intersects(tripleShellObj.getRec()) && health > 0) {
                tripleShellObj.setX(-100);
                tripleShellObj.setY(-100);
                GameUtils.removeList.add(tripleShellObj);
                health-=5;
            } else if (this.getRec().intersects(tripleShellObj.getRec())) {
                //boss生命值为0之后出现爆炸动画
                ExplodeObj explodeObj = new ExplodeObj(x, y);
                GameUtils.explodeObjList.add(explodeObj);
                GameUtils.removeList.add(explodeObj);

                tripleShellObj.setX(-100);
                tripleShellObj.setY(-100);
                this.x = -200;
                this.y = -200;
                GameUtils.removeList.add(this);
                GameCreate.score+=30;

                //游戏胜利（boss血量为0）
                GameCreate.state=4;
            }
        }
        //重新刷新游戏数据
        if(GameCreate.state==3||GameCreate.state==4){
            this.x=-1000;
            this.y=-1000;
            GameUtils.removeList.add(this);
        }
        //通过矩形颜色的变化来表示血条
        //绘制白色矩形
        g.setColor(Color.WHITE);
        g.fillRect(200,40,200,10);
        //绘制红色矩形
        g.setColor(Color.RED);
        g.fillRect(200,40,health*200/500,10);
    }

    @Override
    public Rectangle getRec() {
        return super.getRec();
    }
}
